package com.imooc.miaosha.controller.BackController;

import com.imooc.miaosha.pojo.MiaoshaGoods;
import com.imooc.miaosha.service.SecondKillService;
import com.imooc.miaosha.util.JsonData;
import com.imooc.miaosha.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/manage/miaosha")
public class MiaoShaManageController {
    @Autowired
    SecondKillService secondKillService;

    @RequestMapping("list")
    public JsonData list() {
        return secondKillService.list();
    }

    @RequestMapping("add")
    public JsonData add(@RequestBody MiaoshaGoods miaoshaGoods) {
        Map<String, Object> map = secondKillService.add(miaoshaGoods);
        JsonData jsonData = new JsonData((Integer) map.get("code"));
        jsonData.setMsg((String) map.get("msg"));
        return jsonData;
    }
}
